using Core.SimpleTemp.Common;
using Core.SimpleTemp.Common.PagingQuery;
using Core.SimpleTemp.Entitys;
using Core.SimpleTemp.Repositories;
using Core.Toolkit.Common;
using Core.Toolkit.Core;
using Core.Toolkit.Core.Api;
using Core.Toolkit.Core.Application;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Core.SimpleTemp.Application
{
    [AutoDi()]
    public class CBS_CategoryManageService : BaseAppService<CBS_CategoryManageDto, CBS_CategoryManage, CBS_CategoryManageRepository>
    {
        readonly ExcelHelp _excelHelp;
        public CBS_CategoryManageService(CBS_CategoryManageRepository repository, ExcelHelp excelHelp) : base(repository)
        {
            _excelHelp = excelHelp;
        }



        private LoadPageOffsetModelAuto<CBS_CategoryManage, CBS_CategoryManageDto>
            GetLoadPageOffsetMode(PagingModel<CBS_CategoryManageDto>
                pagingQueryModel)
        {
            var loadPageOffsetModel = this.GetLoadPageOffsetModelAuto(pagingQueryModel);
            var baseQuery = _repository.QueryBase().AsNoTracking();
            loadPageOffsetModel.QueryWhere = this.CreateQRList()

     .Add("ConstructionCategory", "=") //
     .Add("ManageDept", "=");//


            loadPageOffsetModel.BasqQuery = baseQuery;
            loadPageOffsetModel.Order = orderModel => orderModel.CreateTime;
            loadPageOffsetModel.Selector = model => new CBS_CategoryManage()
            {
                Id = model.Id,
                ConstructionCategory = model.ConstructionCategory,//
                ManageDept = model.ManageDept,//
                SysDepartment=model.SysDepartment,
            };
            return loadPageOffsetModel;
        }


        public async Task<IPageModel<CBS_CategoryManageDto>> GetList(PagingModel<CBS_CategoryManageDto>
            pagingQueryModel)
        {
            var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
            return await base.LoadPageOffsetAsync(loadPageOffsetModel);
        }


        public async Task<string>
            Export(PagingModel<CBS_CategoryManageDto>
                pagingQueryModel)
        {
            var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
            var DataList = await this.ExportDataAsync(loadPageOffsetModel);
            var excelData = DataList.Select(model => new
            {
                model.ConstructionCategory,
                ConstructionCategory_title = "",
                model.ManageDept,
                ManageDept_title = "",
            }).ToList();




            return _excelHelp.Create(excelData);
        }

    }

}
